package com.lj.bruth.config;



import io.shardingsphere.api.algorithm.sharding.PreciseShardingValue;
import io.shardingsphere.api.algorithm.sharding.standard.PreciseShardingAlgorithm;

import java.util.Collection;

/**
 * @Author LJ
 * @Description 自定义inline标准分片策略StandardShardingStrategy  精准分表PreciseShardingTableAlgorithm
 * @Date 15:10 2021/1/24
 * @Param
 * @return
 **/
public class PreciseShardingTableAlgorithm implements PreciseShardingAlgorithm<Long> {
    @Override
    public String doSharding(Collection<String> tableNames,
                             PreciseShardingValue<Long> shardingValue) {
        for (String key : tableNames) {
            if (key.endsWith(shardingValue.getValue() % tableNames.size() + "")) {
                return key;
            }
        }
        throw new UnsupportedOperationException();
    }
}
